;;;求幂算法，分治法演算
(define (expt b n)
  (if (= n 0)
    1
    (* b (expt b (- n 1)))))

(define (expt b n)
  (define (expt-iter b counter produce)
    (if (= counter 0)
      product
      (expt-iter b
                 (- counter 1)
                 (* b product))))
  (expt-iter b n 1))

(define (fast-expt b n)
  (define (square m)
    (* m m))
  (cond ((= n 0) 1)
        ((even? n) (square (fast-expt b (/ n 2))))
        (else (* b (fast-expt b (- n 1))))))

;;;反转列表
(define (reverse1 x)
  (if (null? x)
      '()
      (append (reverse1 (cdr x)) (list (car x)))))
(reverse1 (list 1 2 3 4))
